# Makefile for Knowledge Management System

# 默认目标
.PHONY: all
all: build

# 创建static目录并复制前端构建文件
.PHONY: build
build:
	@echo "Creating static directory if it doesn't exist..."
	@mkdir -p static
	@echo "Cleaning old files in static directory..."
	@rm -rf static/*
	@echo "Copying frontend files to static directory..."
	@if [ -d "../frontend/dist" ]; then \
		cp -r ../frontend/dist/* static/; \
		echo "Frontend files copied successfully."; \
	else \
		echo "Error: ../frontend/dist directory not found. Please build the frontend first."; \
		exit 1; \
	fi
	@echo "Building Go application..."
	@go build -o ../knowledge-manage-app .
	@echo "Go application built successfully."

# 清理生成的文件
.PHONY: clean
clean:
	@echo "Cleaning static directory..."
	@rm -rf static/*
	@echo "static directory cleaned."
	@echo "Removing compiled binary..."
	@rm -f ../knowledge-manage-app
	@echo "Compiled binary removed."

# 帮助信息
.PHONY: help
help:
	@echo "Available targets:"
	@echo "  all           - Default target, copies frontend files to static directory"
	@echo "  copy-frontend - Copies frontend files to static directory"
	@echo "  clean         - Removes all files in static directory and removes compiled binary"
	@echo "  help          - Shows this help message" := frontend.GetEmbedFS().(http.FileSystem); ok {